package org.example.synchronizeddemo;

/**
 * 类锁示例1 static形式
 */
public class synchronizedClassStatic4 implements Runnable {

    private static final synchronizedClassStatic4 syn = new synchronizedClassStatic4();

    private static final synchronizedClassStatic4 syn2 = new synchronizedClassStatic4();

    @Override
    public void run() {
        method();
    }


    public static synchronized void method() {
        System.out.println("我是对象锁的方法锁修饰形式，我叫：" + Thread.currentThread().getName());
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread().getName() + "运行结束");
    }

    public static void main(String[] args) {
        Thread thread1 = new Thread(syn);
        Thread thread2 = new Thread(syn2);
        thread1.start();
        thread2.start();
        while (thread1.isAlive() || thread2.isAlive()) {

        }

        System.out.println("结束");
    }

}
